home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 July: Mac OS SDK / Dev.CD Jul 00 SDK2.toast / Development Kits / Cross Platform / QuickTime 4.1.2 Windows SDK / CIncludes / UnicodeUtilities.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-04-12  |  17.5 KB  |  485 lines  |  [TEXT/R*ch]

  1. /*
  2.      File:        UnicodeUtilities.h
  3.  
  4.      Contains:    Types, constants, prototypes for Unicode Utilities (Unicode input and text utils)
  5.  
  6.      Version:    Technology:    Mac OS 9.0
  7.                  Release:    QuickTime 4.1
  8.  
  9.      Copyright:    (c) 1997-1999 by Apple Computer, Inc., all rights reserved.
  10.  
  11.      Bugs?:        For bug reports, consult the following page on
  12.                  the World Wide Web:
  13.  
  14.                      http://developer.apple.com/bugreporter/
  15.  
  16. */
  17. #ifndef __UNICODEUTILITIES__
  18. #define __UNICODEUTILITIES__
  19.  
  20. #ifndef __MACTYPES__
  21.     #include <MacTypes.h>
  22. #endif
  23.  
  24.  
  25. #ifndef __MACLOCALES__
  26.     #include <MacLocales.h>
  27. #endif
  28.  
  29. #ifndef __TEXTCOMMON__
  30.     #include <TextCommon.h>
  31. #endif
  32.  
  33.  
  34.  
  35. #if PRAGMA_ONCE
  36. #pragma once
  37. #endif
  38.  
  39. #ifdef __cplusplus
  40. extern "C" {
  41. #endif
  42.  
  43. #if PRAGMA_IMPORT
  44. #pragma import on
  45. #endif
  46.  
  47. #if PRAGMA_STRUCT_ALIGN
  48.     #pragma options align=mac68k
  49. #elif PRAGMA_STRUCT_PACKPUSH
  50.     #pragma pack(push, 2)
  51. #elif PRAGMA_STRUCT_PACK
  52.     #pragma pack(2)
  53. #endif
  54.  
  55. /*
  56.    -------------------------------------------------------------------------------------------------
  57.    CONSTANTS & DATA STRUCTURES for UCKeyTranslate & UCKeyboardLayout ('uchr' resource)
  58.    -------------------------------------------------------------------------------------------------
  59. */
  60.  
  61. /*
  62.    -------------------------------------------------------------------------------------------------
  63.    UCKeyOutput & related stuff
  64.    The interpretation of UCKeyOutput depends on bits 15-14.
  65.    If they are 01, then bits 0-13 are an index in UCKeyStateRecordsIndex (resource-wide list).
  66.    If they are 10, then bits 0-13 are an index in UCKeySequenceDataIndex (resource-wide list),
  67.      or if UCKeySequenceDataIndex is not present or the index is beyond the end of the list,
  68.      then bits 0-15 are a single Unicode character.
  69.    Otherwise, bits 0-15 are a single Unicode character; a value of 0xFFFE-0xFFFF means no character
  70.      output.
  71.    UCKeyCharSeq is similar, but does not support indices in UCKeyStateRecordsIndex. For bits 15-14:
  72.    If they are 10, then bits 0-13 are an index in UCKeySequenceDataIndex (resource-wide list),
  73.      or if UCKeySequenceDataIndex is not present or the index is beyond the end of the list,
  74.      then bits 0-15 are a single Unicode character.
  75.    Otherwise, bits 0-15 are a single Unicode character; a value of 0xFFFE-0xFFFF means no character
  76.      output.
  77.    -------------------------------------------------------------------------------------------------
  78. */
  79.  
  80. typedef UInt16                             UCKeyOutput;
  81. typedef UInt16                             UCKeyCharSeq;
  82. enum {
  83.     kUCKeyOutputStateIndexMask    = 0x4000,
  84.     kUCKeyOutputSequenceIndexMask = 0x8000,
  85.     kUCKeyOutputTestForIndexMask = 0xC000,                        /* test bits 14-15*/
  86.     kUCKeyOutputGetIndexMask    = 0x3FFF                        /* get bits 0-13*/
  87. };
  88.  
  89. /*
  90.    -------------------------------------------------------------------------------------------------
  91.    UCKeyStateRecord & related stuff
  92.    The UCKeyStateRecord information is used as follows. If the current state is zero,
  93.    output stateZeroCharData and set the state to stateZeroNextState. If the current state
  94.    is non-zero and there is an entry for it in stateEntryData, then output the corresponding
  95.    charData and set the state to nextState. Otherwise, output the state terminator from
  96.    UCKeyStateTerminators for the current state (or nothing if there is no UCKeyStateTerminators
  97.    table or it has no entry for the current state), then output stateZeroCharData and set the
  98.    state to stateZeroNextState.
  99.    -------------------------------------------------------------------------------------------------
  100. */
  101.  
  102.  
  103. struct UCKeyStateRecord {
  104.     UCKeyCharSeq                     stateZeroCharData;
  105.     UInt16                             stateZeroNextState;
  106.     UInt16                             stateEntryCount;
  107.     UInt16                             stateEntryFormat;
  108.                                                                 /* This is followed by an array of stateEntryCount elements*/
  109.                                                                 /* in the specified format. Here we just show a dummy array.*/
  110.     UInt32                             stateEntryData[1];
  111. };
  112. typedef struct UCKeyStateRecord            UCKeyStateRecord;
  113. /*
  114.    Here are the codes for entry formats currently defined.
  115.    Each entry maps from curState to charData and nextState.
  116. */
  117. enum {
  118.     kUCKeyStateEntryTerminalFormat = 0x0001,
  119.     kUCKeyStateEntryRangeFormat    = 0x0002
  120. };
  121.  
  122. /*
  123.    For UCKeyStateEntryTerminal -
  124.    nextState is always 0, so we don't have a field for it
  125. */
  126.  
  127.  
  128. struct UCKeyStateEntryTerminal {
  129.     UInt16                             curState;
  130.     UCKeyCharSeq                     charData;
  131. };
  132. typedef struct UCKeyStateEntryTerminal    UCKeyStateEntryTerminal;
  133. /*
  134.    For UCKeyStateEntryRange -
  135.    If curState >= curStateStart and curState <= curStateStart+curStateRange,
  136.    then it matches the entry, and we transform charData and nextState as follows:
  137.    If charData < 0xFFFE, then charData += (curState-curStateStart)*deltaMultiplier
  138.    If nextState != 0, then nextState += (curState-curStateStart)*deltaMultiplier
  139. */
  140.  
  141. struct UCKeyStateEntryRange {
  142.     UInt16                             curStateStart;
  143.     UInt8                             curStateRange;
  144.     UInt8                             deltaMultiplier;
  145.     UCKeyCharSeq                     charData;
  146.     UInt16                             nextState;
  147. };
  148. typedef struct UCKeyStateEntryRange        UCKeyStateEntryRange;
  149. /*
  150.    -------------------------------------------------------------------------------------------------
  151.    UCKeyboardLayout & related stuff
  152.    The UCKeyboardLayout struct given here is only for the resource header. It specifies
  153.    offsets to the various subtables which each have their own structs, given below.
  154.    The keyboardTypeHeadList array selects table offsets that depend on keyboardType. The
  155.    first entry in keyboardTypeHeadList is the default entry, which will be used if the
  156.    keyboardType passed to UCKeyTranslate does not match any other entry - i.e. does not fall
  157.    within the range keyboardTypeFirst..keyboardTypeLast for some entry. The first entry
  158.    should have keyboardTypeFirst = keyboardTypeLast = 0.
  159.    -------------------------------------------------------------------------------------------------
  160. */
  161.  
  162. struct UCKeyboardTypeHeader {
  163.     UInt32                             keyboardTypeFirst;            /* first keyboardType in this entry*/
  164.     UInt32                             keyboardTypeLast;            /* last keyboardType in this entry*/
  165.     ByteOffset                         keyModifiersToTableNumOffset; /* required*/
  166.     ByteOffset                         keyToCharTableIndexOffset;    /* required*/
  167.     ByteOffset                         keyStateRecordsIndexOffset;    /* 0 => no table*/
  168.     ByteOffset                         keyStateTerminatorsOffset;    /* 0 => no table*/
  169.     ByteOffset                         keySequenceDataIndexOffset;    /* 0 => no table*/
  170. };
  171. typedef struct UCKeyboardTypeHeader        UCKeyboardTypeHeader;
  172.  
  173. struct UCKeyboardLayout {
  174.                                                                 /* header only; other tables accessed via offsets*/
  175.     UInt16                             keyLayoutHeaderFormat;        /* =kUCKeyLayoutHeaderFormat*/
  176.     UInt16                             keyLayoutDataVersion;        /* 0x0100 = 1.0, 0x0110 = 1.1, etc.*/
  177.     ByteOffset                         keyLayoutFeatureInfoOffset;    /* may be 0                                    */
  178.     ItemCount                         keyboardTypeCount;            /* Dimension for keyboardTypeHeadList[]        */
  179.     UCKeyboardTypeHeader             keyboardTypeList[1];
  180. };
  181. typedef struct UCKeyboardLayout            UCKeyboardLayout;
  182. /* -------------------------------------------------------------------------------------------------*/
  183.  
  184. struct UCKeyLayoutFeatureInfo {
  185.     UInt16                             keyLayoutFeatureInfoFormat;    /* =kUCKeyLayoutFeatureInfoFormat*/
  186.     UInt16                             reserved;
  187.     UniCharCount                     maxOutputStringLength;        /* longest possible output string*/
  188. };
  189. typedef struct UCKeyLayoutFeatureInfo    UCKeyLayoutFeatureInfo;
  190. /* -------------------------------------------------------------------------------------------------*/
  191.  
  192. struct UCKeyModifiersToTableNum {
  193.     UInt16                             keyModifiersToTableNumFormat; /* =kUCKeyModifiersToTableNumFormat*/
  194.     UInt16                             defaultTableNum;            /* For modifier combos not in tableNum[]*/
  195.     ItemCount                         modifiersCount;                /* Dimension for tableNum[]*/
  196.     UInt8                             tableNum[1];
  197.  
  198.                                                                 /* Then there is padding to a 4-byte boundary with bytes containing 0, if necessary.*/
  199. };
  200. typedef struct UCKeyModifiersToTableNum    UCKeyModifiersToTableNum;
  201. /* -------------------------------------------------------------------------------------------------*/
  202.  
  203. struct UCKeyToCharTableIndex {
  204.     UInt16                             keyToCharTableIndexFormat;    /* =kUCKeyToCharTableIndexFormat*/
  205.     UInt16                             keyToCharTableSize;            /* Max keyCode (128 for ADB keyboards)*/
  206.     ItemCount                         keyToCharTableCount;        /* Dimension for keyToCharTableOffsets[] (usually 6 to 12 tables)*/
  207.     ByteOffset                         keyToCharTableOffsets[1];
  208.  
  209.                                                                 /* Each offset in keyToCharTableOffsets is from the beginning of the resource to a*/
  210.                                                                 /* table as follows:*/
  211.                                                                 /*    UCKeyOutput        keyToCharData[keyToCharTableSize];*/
  212.                                                                 /* These tables follow the UCKeyToCharTableIndex.*/
  213.                                                                 /* Then there is padding to a 4-byte boundary with bytes containing 0, if necessary.*/
  214. };
  215. typedef struct UCKeyToCharTableIndex    UCKeyToCharTableIndex;
  216. /* -------------------------------------------------------------------------------------------------*/
  217.  
  218. struct UCKeyStateRecordsIndex {
  219.     UInt16                             keyStateRecordsIndexFormat;    /* =kUCKeyStateRecordsIndexFormat*/
  220.     UInt16                             keyStateRecordCount;        /* Dimension for keyStateRecordOffsets[]*/
  221.     ByteOffset                         keyStateRecordOffsets[1];
  222.  
  223.                                                                 /* Each offset in keyStateRecordOffsets is from the beginning of the resource to a*/
  224.                                                                 /* UCKeyStateRecord. These UCKeyStateRecords follow the keyStateRecordOffsets[] array.*/
  225.                                                                 /* Then there is padding to a 4-byte boundary with bytes containing 0, if necessary.*/
  226. };
  227. typedef struct UCKeyStateRecordsIndex    UCKeyStateRecordsIndex;
  228. /* -------------------------------------------------------------------------------------------------*/
  229.  
  230. struct UCKeyStateTerminators {
  231.     UInt16                             keyStateTerminatorsFormat;    /* =kUCKeyStateTerminatorsFormat*/
  232.     UInt16                             keyStateTerminatorCount;    /* Dimension for keyStateTerminators[] (# of nonzero states)*/
  233.     UCKeyCharSeq                     keyStateTerminators[1];
  234.  
  235.                                                                 /* Note: keyStateTerminators[0] is terminator for state 1, etc.*/
  236.                                                                 /* Then there is padding to a 4-byte boundary with bytes containing 0, if necessary.*/
  237. };
  238. typedef struct UCKeyStateTerminators    UCKeyStateTerminators;
  239. /* -------------------------------------------------------------------------------------------------*/
  240.  
  241. struct UCKeySequenceDataIndex {
  242.     UInt16                             keySequenceDataIndexFormat;    /* =kUCKeySequenceDataIndexFormat*/
  243.     UInt16                             charSequenceCount;            /* Dimension of charSequenceOffsets[] is charSequenceCount+1*/
  244.     UInt16                             charSequenceOffsets[1];
  245.  
  246.                                                                 /* Each offset in charSequenceOffsets is in bytes, from the beginning of*/
  247.                                                                 /* UCKeySequenceDataIndex to a sequence of UniChars; the next offset indicates the*/
  248.                                                                 /* end of the sequence. The UniChar sequences follow the UCKeySequenceDataIndex.*/
  249.                                                                 /* Then there is padding to a 4-byte boundary with bytes containing 0, if necessary.*/
  250. };
  251. typedef struct UCKeySequenceDataIndex    UCKeySequenceDataIndex;
  252. /* -------------------------------------------------------------------------------------------------*/
  253. /* Current format codes for the various tables (bits 12-15 indicate which table)*/
  254.  
  255. enum {
  256.     kUCKeyLayoutHeaderFormat    = 0x1002,
  257.     kUCKeyLayoutFeatureInfoFormat = 0x2001,
  258.     kUCKeyModifiersToTableNumFormat = 0x3001,
  259.     kUCKeyToCharTableIndexFormat = 0x4001,
  260.     kUCKeyStateRecordsIndexFormat = 0x5001,
  261.     kUCKeyStateTerminatorsFormat = 0x6001,
  262.     kUCKeySequenceDataIndexFormat = 0x7001
  263. };
  264.  
  265.  
  266. /*
  267.    -------------------------------------------------------------------------------------------------
  268.    Constants for keyAction parameter in UCKeyTranslate() 
  269.    -------------------------------------------------------------------------------------------------
  270. */
  271.  
  272. enum {
  273.     kUCKeyActionDown            = 0,                            /* key is going down*/
  274.     kUCKeyActionUp                = 1,                            /* key is going up*/
  275.     kUCKeyActionAutoKey            = 2,                            /* auto-key down*/
  276.     kUCKeyActionDisplay            = 3                                /* get information for key display (as in Key Caps)            */
  277. };
  278.  
  279. /*
  280.    -------------------------------------------------------------------------------------------------
  281.    Bit assignments & masks for keyTranslateOptions parameter in UCKeyTranslate() 
  282.    -------------------------------------------------------------------------------------------------
  283. */
  284.  
  285. enum {
  286.     kUCKeyTranslateNoDeadKeysBit = 0                            /* Prevents setting any new dead-key states*/
  287. };
  288.  
  289. enum {
  290.     kUCKeyTranslateNoDeadKeysMask = 1L << kUCKeyTranslateNoDeadKeysBit
  291. };
  292.  
  293. /*
  294.    -------------------------------------------------------------------------------------------------
  295.    CONSTANTS & DATA STRUCTURES for Unicode Collation
  296.    -------------------------------------------------------------------------------------------------
  297. */
  298. /* constant for LocaleOperationClass*/
  299. enum {
  300.     kUnicodeCollationClass        = FOUR_CHAR_CODE('ucol')
  301. };
  302.  
  303. typedef struct OpaqueCollatorRef*         CollatorRef;
  304.  
  305. typedef UInt32 UCCollateOptions;
  306. enum {
  307.                                                                 /* Sensitivity options*/
  308.     kUCCollateComposeInsensitiveMask = 1L << 1,
  309.     kUCCollateWidthInsensitiveMask = 1L << 2,
  310.     kUCCollateCaseInsensitiveMask = 1L << 3,
  311.     kUCCollateDiacritInsensitiveMask = 1L << 4,                    /* Other general options */
  312.     kUCCollatePunctuationSignificantMask = 1L << 15,            /* Number-handling options */
  313.     kUCCollateDigitsOverrideMask = 1L << 16,
  314.     kUCCollateDigitsAsNumberMask = 1L << 17
  315. };
  316.  
  317. enum {
  318.     kUCCollateStandardOptions    = kUCCollateComposeInsensitiveMask | kUCCollateWidthInsensitiveMask
  319. };
  320.  
  321. /*
  322.    Special values to specify various invariant orders for UCCompareTextNoLocale.
  323.    These values use the high 8 bits of UCCollateOptions.
  324. */
  325. enum {
  326.     kUCCollateTypeHFSExtended    = 1
  327. };
  328.  
  329. /* These constants are used for masking and shifting the invariant order type.*/
  330. enum {
  331.     kUCCollateTypeSourceMask    = 0x000000FF,
  332.     kUCCollateTypeShiftBits        = 24
  333. };
  334.  
  335. enum {
  336.     kUCCollateTypeMask            = kUCCollateTypeSourceMask << kUCCollateTypeShiftBits
  337. };
  338.  
  339.  
  340. typedef UInt32                             UCCollationValue;
  341. /*
  342.    -------------------------------------------------------------------------------------------------
  343.    CONSTANTS & DATA STRUCTURES for Unicode TextBreak
  344.    -------------------------------------------------------------------------------------------------
  345. */
  346. /* constant for LocaleOperationClass*/
  347. enum {
  348.     kUnicodeTextBreakClass        = FOUR_CHAR_CODE('ubrk')
  349. };
  350.  
  351. typedef struct OpaqueTextBreakLocatorRef*  TextBreakLocatorRef;
  352.  
  353. typedef UInt32 UCTextBreakType;
  354. enum {
  355.     kUCTextBreakCharMask        = 1L << 0,
  356.     kUCTextBreakClusterMask        = 1L << 2,
  357.     kUCTextBreakWordMask        = 1L << 4,
  358.     kUCTextBreakLineMask        = 1L << 6
  359. };
  360.  
  361.  
  362. typedef UInt32 UCTextBreakOptions;
  363. enum {
  364.     kUCTextBreakLeadingEdgeMask    = 1L << 0,
  365.     kUCTextBreakGoBackwardsMask    = 1L << 1,
  366.     kUCTextBreakIterateMask        = 1L << 2
  367. };
  368.  
  369. /*
  370.    -------------------------------------------------------------------------------------------------
  371.    FUNCTION PROTOTYPES
  372.    -------------------------------------------------------------------------------------------------
  373. */
  374.  
  375. EXTERN_API( OSStatus )
  376. UCKeyTranslate                    (const UCKeyboardLayout * keyLayoutPtr,
  377.                                  UInt16                 virtualKeyCode,
  378.                                  UInt16                 keyAction,
  379.                                  UInt32                 modifierKeyState,
  380.                                  UInt32                 keyboardType,
  381.                                  OptionBits             keyTranslateOptions,
  382.                                  UInt32 *                deadKeyState,
  383.                                  UniCharCount             maxStringLength,
  384.                                  UniCharCount *            actualStringLength,
  385.                                  UniChar                 unicodeString[]);
  386.  
  387. /* Standard collation functions*/
  388. EXTERN_API_C( OSStatus )
  389. UCCreateCollator                (LocaleRef                 locale,
  390.                                  LocaleOperationVariant  opVariant,
  391.                                  UCCollateOptions         options,
  392.                                  CollatorRef *            collatorRef);
  393.  
  394. EXTERN_API_C( OSStatus )
  395. UCGetCollationKey                (CollatorRef             collatorRef,
  396.                                  const UniChar *        textPtr,
  397.                                  UniCharCount             textLength,
  398.                                  ItemCount                 maxKeySize,
  399.                                  ItemCount *            actualKeySize,
  400.                                  UCCollationValue         collationKey[]);
  401.  
  402. EXTERN_API_C( OSStatus )
  403. UCCompareCollationKeys            (const UCCollationValue * key1Ptr,
  404.                                  ItemCount                 key1Length,
  405.                                  const UCCollationValue * key2Ptr,
  406.                                  ItemCount                 key2Length,
  407.                                  Boolean *                equivalent,
  408.                                  SInt32 *                order);
  409.  
  410. EXTERN_API_C( OSStatus )
  411. UCCompareText                    (CollatorRef             collatorRef,
  412.                                  const UniChar *        text1Ptr,
  413.                                  UniCharCount             text1Length,
  414.                                  const UniChar *        text2Ptr,
  415.                                  UniCharCount             text2Length,
  416.                                  Boolean *                equivalent,
  417.                                  SInt32 *                order);
  418.  
  419. EXTERN_API_C( OSStatus )
  420. UCDisposeCollator                (CollatorRef *            collatorRef);
  421.  
  422. /* Simple collation using default locale*/
  423.  
  424. EXTERN_API_C( OSStatus )
  425. UCCompareTextDefault            (UCCollateOptions         options,
  426.                                  const UniChar *        text1Ptr,
  427.                                  UniCharCount             text1Length,
  428.                                  const UniChar *        text2Ptr,
  429.                                  UniCharCount             text2Length,
  430.                                  Boolean *                equivalent,
  431.                                  SInt32 *                order);
  432.  
  433.  
  434. /* Simple locale-independent collation*/
  435.  
  436. EXTERN_API_C( OSStatus )
  437. UCCompareTextNoLocale            (UCCollateOptions         options,
  438.                                  const UniChar *        text1Ptr,
  439.                                  UniCharCount             text1Length,
  440.                                  const UniChar *        text2Ptr,
  441.                                  UniCharCount             text2Length,
  442.                                  Boolean *                equivalent,
  443.                                  SInt32 *                order);
  444.  
  445. /* Standard text break (text boundary) functions*/
  446. EXTERN_API_C( OSStatus )
  447. UCCreateTextBreakLocator        (LocaleRef                 locale,
  448.                                  LocaleOperationVariant  opVariant,
  449.                                  UCTextBreakType         breakTypes,
  450.                                  TextBreakLocatorRef *    breakRef);
  451.  
  452. EXTERN_API_C( OSStatus )
  453. UCFindTextBreak                    (TextBreakLocatorRef     breakRef,
  454.                                  UCTextBreakType         breakType,
  455.                                  UCTextBreakOptions     options,
  456.                                  const UniChar *        textPtr,
  457.                                  UniCharCount             textLength,
  458.                                  UniCharArrayOffset     startOffset,
  459.                                  UniCharArrayOffset *    breakOffset);
  460.  
  461. EXTERN_API_C( OSStatus )
  462. UCDisposeTextBreakLocator        (TextBreakLocatorRef *    breakRef);
  463.  
  464.  
  465. #if PRAGMA_STRUCT_ALIGN
  466.     #pragma options align=reset
  467. #elif PRAGMA_STRUCT_PACKPUSH
  468.     #pragma pack(pop)
  469. #elif PRAGMA_STRUCT_PACK
  470.     #pragma pack()
  471. #endif
  472.  
  473. #ifdef PRAGMA_IMPORT_OFF
  474. #pragma import off
  475. #elif PRAGMA_IMPORT
  476. #pragma import reset
  477. #endif
  478.  
  479. #ifdef __cplusplus
  480. }
  481. #endif
  482.  
  483. #endif /* __UNICODEUTILITIES__ */
  484.  
  485.